public class Solution1664 {
    public int waysToMakeFair(int[] nums) {
        int[] f=new int[nums.length];
        for (int i=nums.length-1;i>=0;i--){
            if (i+2>=nums.length){
                f[i]=nums[i];
            }else {
                f[i]=f[i+2]+nums[i];
            }
        }
        int ans=0,odd=0,eval=0;
        for (int i=0;i<nums.length;i++){
            int x=i+1>=nums.length?0:f[i+1];
            int y=i+2>=nums.length?0:f[i+2];
            if (i%2==0){
                if (eval+x==odd+y){
                    ans++;
                }
                eval+=nums[i];
            }else {
                if (eval+y==odd+x){
                    ans++;
                }
                odd+=nums[i];
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1664().waysToMakeFair(new int[]{2,1,6,4}));
    }
}
